<?php

/**
 * @author Jose Luis Quintana
 * @copyright 2010 LBN Studio
 */
defined("JL") or die("");

define("JLPATH_COUNTER", "5G7KsI3Utn55YukQyNtAqU44/10kI3Utn55Yxu5r.txt");
define("JLSESSION_COUNTER", "JLSESSION_COUNTER");

function isSetNoEmpty($value) {
    $value = trim($value);
    return (isset($value) && !empty($value)) ? true : false;
}

function getData() {
    $count = 0;
    if (file_exists(JLPATH_COUNTER)) {
        $fp = fopen(JLPATH_COUNTER, "r+");
        flock($fp, 1);
        $count = fgets($fp, 4096);
        $count += 1;
        fseek($fp, 0);
        fputs($fp, $count);
        flock($fp, 3);
        fclose($fp);
    }

    return $count;
}

if (!isSetNoEmpty($_SESSION[JLSESSION_COUNTER])) {
    $_SESSION[JLSESSION_COUNTER] = getData();
}

$count = $_SESSION[JLSESSION_COUNTER];
echo $count;
